package com.example.demo.io;

import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
import java.nio.ByteBuffer;

public class Client {

    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("127.0.0.1", 9999);
        OutputStream out = socket.getOutputStream();
        byte[] array ="hello".getBytes();
        int totalLength = 4 + array.length;
        ByteBuffer buffer = ByteBuffer.allocate(totalLength);
        buffer.putInt(totalLength).put(array);
        out.write(buffer.array());
        out.flush();
        out.close();

    }
}
